package com.ruoyi.web.controller.ziran;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ziran.domain.ZrPaperItem;
import com.ruoyi.ziran.service.IZrPaperItemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷题库关联Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Controller
@RequestMapping("/ziran/zrPaperItem")
public class ZrPaperItemController extends BaseController
{
    private String prefix = "ziran/zrPaperItem";

    @Autowired
    private IZrPaperItemService zrPaperItemService;

    //@RequiresPermissions("ziran:zrPaperItem:view")
    @GetMapping()
    public String zrPaperItem()
    {
        return prefix + "/zrPaperItem";
    }

    /**
     * 查询试卷题库关联列表
     */
    //@RequiresPermissions("ziran:zrPaperItem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZrPaperItem zrPaperItem)
    {
        startPage();
        List<ZrPaperItem> list = zrPaperItemService.selectZrPaperItemList(zrPaperItem);
        return getDataTable(list);
    }

    /**
     * 导出试卷题库关联列表
     */
    //@RequiresPermissions("ziran:zrPaperItem:export")
    @Log(title = "试卷题库关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZrPaperItem zrPaperItem)
    {
        List<ZrPaperItem> list = zrPaperItemService.selectZrPaperItemList(zrPaperItem);
        ExcelUtil<ZrPaperItem> util = new ExcelUtil<ZrPaperItem>(ZrPaperItem.class);
        return util.exportExcel(list, "试卷题库关联数据");
    }

    /**
     * 新增试卷题库关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷题库关联
     */
    //@RequiresPermissions("ziran:zrPaperItem:add")
    @Log(title = "试卷题库关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZrPaperItem zrPaperItem)
    {
        return toAjax(zrPaperItemService.insertZrPaperItem(zrPaperItem));
    }

    /**
     * 修改试卷题库关联
     */
    //@RequiresPermissions("ziran:zrPaperItem:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrPaperItem zrPaperItem = zrPaperItemService.selectZrPaperItemById(id);
        mmap.put("zrPaperItem", zrPaperItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷题库关联
     */
    //@RequiresPermissions("ziran:zrPaperItem:edit")
    @Log(title = "试卷题库关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZrPaperItem zrPaperItem)
    {
        return toAjax(zrPaperItemService.updateZrPaperItem(zrPaperItem));
    }

    /**
     * 删除试卷题库关联
     */
    //@RequiresPermissions("ziran:zrPaperItem:remove")
    @Log(title = "试卷题库关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zrPaperItemService.deleteZrPaperItemByIds(ids));
    }
}
